package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Slf4j
@RestController
public class SessionController {
    //设置值
    @GetMapping("/session1")
    public Result session1(HttpSession session){
        session.setAttribute("loginUser","name");
        return Result.success();
    }
    //取值
    @GetMapping("/session2")
    public Result session2(HttpServletRequest req){
        Object loginUser = req.getSession().getAttribute("loginUser");
        System.out.println("loginUser = "+loginUser);
        return Result.success();
    }
}
